// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Cloud Commerce Consumer Procurement API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_commerce_consumer_procurement_v1::client::LicenseManagementService;
/// let client = LicenseManagementService::builder().build().await?;
/// // use `client` to make requests to the Cloud Commerce Consumer Procurement API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Service for managing licenses.
///
/// # Configuration
///
/// To configure `LicenseManagementService` use the `with_*` methods in the type returned
/// by [builder()][LicenseManagementService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://cloudcommerceconsumerprocurement.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::license_management_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::license_management_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `LicenseManagementService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `LicenseManagementService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct LicenseManagementService {
    inner: std::sync::Arc<dyn super::stub::dynamic::LicenseManagementService>,
}

impl LicenseManagementService {
    /// Returns a builder for [LicenseManagementService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_commerce_consumer_procurement_v1::client::LicenseManagementService;
    /// let client = LicenseManagementService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::license_management_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::license_management_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::LicenseManagementService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<
        std::sync::Arc<dyn super::stub::dynamic::LicenseManagementService>,
    > {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::LicenseManagementService> {
        super::transport::LicenseManagementService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::LicenseManagementService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::LicenseManagementService::new)
    }

    /// Gets the license pool.
    pub fn get_license_pool(&self) -> super::builder::license_management_service::GetLicensePool {
        super::builder::license_management_service::GetLicensePool::new(self.inner.clone())
    }

    /// Updates the license pool if one exists for this Order.
    pub fn update_license_pool(
        &self,
    ) -> super::builder::license_management_service::UpdateLicensePool {
        super::builder::license_management_service::UpdateLicensePool::new(self.inner.clone())
    }

    /// Assigns a license to a user.
    pub fn assign(&self) -> super::builder::license_management_service::Assign {
        super::builder::license_management_service::Assign::new(self.inner.clone())
    }

    /// Unassigns a license from a user.
    pub fn unassign(&self) -> super::builder::license_management_service::Unassign {
        super::builder::license_management_service::Unassign::new(self.inner.clone())
    }

    /// Enumerates all users assigned a license.
    pub fn enumerate_licensed_users(
        &self,
    ) -> super::builder::license_management_service::EnumerateLicensedUsers {
        super::builder::license_management_service::EnumerateLicensedUsers::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::license_management_service::GetOperation {
        super::builder::license_management_service::GetOperation::new(self.inner.clone())
    }
}

/// Implements a client for the Cloud Commerce Consumer Procurement API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_commerce_consumer_procurement_v1::client::ConsumerProcurementService;
/// let client = ConsumerProcurementService::builder().build().await?;
/// // use `client` to make requests to the Cloud Commerce Consumer Procurement API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// ConsumerProcurementService allows customers to make purchases of products
/// served by the Cloud Commerce platform.
///
/// When purchases are made, the
/// [ConsumerProcurementService][google.cloud.commerce.consumer.procurement.v1.ConsumerProcurementService]
/// programs the appropriate backends, including both Google's own
/// infrastructure, as well as third-party systems, and to enable billing setup
/// for charging for the procured item.
///
/// [google.cloud.commerce.consumer.procurement.v1.ConsumerProcurementService]: crate::client::ConsumerProcurementService
///
/// # Configuration
///
/// To configure `ConsumerProcurementService` use the `with_*` methods in the type returned
/// by [builder()][ConsumerProcurementService::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://cloudcommerceconsumerprocurement.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::consumer_procurement_service::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::consumer_procurement_service::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `ConsumerProcurementService` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `ConsumerProcurementService` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct ConsumerProcurementService {
    inner: std::sync::Arc<dyn super::stub::dynamic::ConsumerProcurementService>,
}

impl ConsumerProcurementService {
    /// Returns a builder for [ConsumerProcurementService].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_commerce_consumer_procurement_v1::client::ConsumerProcurementService;
    /// let client = ConsumerProcurementService::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::consumer_procurement_service::ClientBuilder {
        gax::client_builder::internal::new_builder(
            super::builder::consumer_procurement_service::client::Factory,
        )
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::ConsumerProcurementService + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<
        std::sync::Arc<dyn super::stub::dynamic::ConsumerProcurementService>,
    > {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ConsumerProcurementService> {
        super::transport::ConsumerProcurementService::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::ConsumerProcurementService> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::ConsumerProcurementService::new)
    }

    /// Creates a new [Order][google.cloud.commerce.consumer.procurement.v1.Order].
    ///
    /// This API only supports GCP spend-based committed use
    /// discounts specified by GCP documentation.
    ///
    /// The returned long-running operation is in-progress until the backend
    /// completes the creation of the resource. Once completed, the order is
    /// in
    /// [OrderState.ORDER_STATE_ACTIVE][google.cloud.commerce.consumer.procurement.v1.OrderState.ORDER_STATE_ACTIVE].
    /// In case of failure, the order resource will be removed.
    ///
    /// [google.cloud.commerce.consumer.procurement.v1.Order]: crate::model::Order
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn place_order(&self) -> super::builder::consumer_procurement_service::PlaceOrder {
        super::builder::consumer_procurement_service::PlaceOrder::new(self.inner.clone())
    }

    /// Returns the requested
    /// [Order][google.cloud.commerce.consumer.procurement.v1.Order] resource.
    ///
    /// [google.cloud.commerce.consumer.procurement.v1.Order]: crate::model::Order
    pub fn get_order(&self) -> super::builder::consumer_procurement_service::GetOrder {
        super::builder::consumer_procurement_service::GetOrder::new(self.inner.clone())
    }

    /// Lists [Order][google.cloud.commerce.consumer.procurement.v1.Order]
    /// resources that the user has access to, within the scope of the parent
    /// resource.
    ///
    /// [google.cloud.commerce.consumer.procurement.v1.Order]: crate::model::Order
    pub fn list_orders(&self) -> super::builder::consumer_procurement_service::ListOrders {
        super::builder::consumer_procurement_service::ListOrders::new(self.inner.clone())
    }

    /// Modifies an existing
    /// [Order][google.cloud.commerce.consumer.procurement.v1.Order] resource.
    ///
    /// [google.cloud.commerce.consumer.procurement.v1.Order]: crate::model::Order
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn modify_order(&self) -> super::builder::consumer_procurement_service::ModifyOrder {
        super::builder::consumer_procurement_service::ModifyOrder::new(self.inner.clone())
    }

    /// Cancels an existing
    /// [Order][google.cloud.commerce.consumer.procurement.v1.Order]. Every product
    /// procured in the Order will be cancelled.
    ///
    /// [google.cloud.commerce.consumer.procurement.v1.Order]: crate::model::Order
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn cancel_order(&self) -> super::builder::consumer_procurement_service::CancelOrder {
        super::builder::consumer_procurement_service::CancelOrder::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::consumer_procurement_service::GetOperation {
        super::builder::consumer_procurement_service::GetOperation::new(self.inner.clone())
    }
}
